﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WOS.Logging
{
    public static class LogExtensions
    {
        public static LogTag[] ToTags(this LogEntry[] entries)
        {
            var query = from entry in entries
                        from tag in entry.Source.Tags
                        select tag;

            return query.Distinct().ToArray();
        }

        public static LogEntry[] Filter(this LogEntry[] entries, LogSource[] sources, LogTag[] tags)
        {
            var query = from entry in entries
                        where sources.Length == 0 || sources.Any(x => entry.Source.IsChildOf(x))
                        where tags.Length == 0 || tags.Join(entry.Source.Tags, x => x, x => x, (x, y) => true).Any()
                        select entry;

            return query.ToArray();
        }
    }
}
